package com.ruoyi.cloud.controller;

import com.ruoyi.cloud.domain.TbCloudCar;
import com.ruoyi.cloud.service.ITbCloudCarService;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

import static com.ruoyi.common.core.utils.PageUtils.startPage;

/**
 * @program: RuoYi-Cloud-master
 * @ClassName CloudCarController
 * @description:
 * @author:
 * @create: 2023-11-29 14:39
 * @Version 1.0
 **/
@RestController
@RequestMapping("/car")
public class CloudCarController extends BaseController {
    @Autowired
    private ITbCloudCarService tbCloudCarService;

    /**
     * 查询冷链车数据列表
     */
    @RequiresPermissions("cloud:car:list")
    @GetMapping("/list")
    public TableDataInfo list(TbCloudCar tbCloudCar)
    {
        startPage();
        List<TbCloudCar> list = tbCloudCarService.selectTbCloudCarList(tbCloudCar);
        return getDataTable(list);
    }

    /**
     * 导出冷链车数据列表
     */
    @RequiresPermissions("cloud:car:export")
    @Log(title = "冷链车数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbCloudCar tbCloudCar)
    {
        List<TbCloudCar> list = tbCloudCarService.selectTbCloudCarList(tbCloudCar);
        ExcelUtil<TbCloudCar> util = new ExcelUtil<TbCloudCar>(TbCloudCar.class);
        util.exportExcel(response, list, "冷链车数据数据");
    }

    /**
     * 获取冷链车数据详细信息
     */
    @RequiresPermissions("cloud:car:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbCloudCarService.selectTbCloudCarById(id));
    }

    /**
     * 新增冷链车数据
     */
    @RequiresPermissions("cloud:car:add")
    @Log(title = "冷链车数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbCloudCar tbCloudCar)
    {
        return toAjax(tbCloudCarService.insertTbCloudCar(tbCloudCar));
    }

    /**
     * 修改冷链车数据
     */
    @RequiresPermissions("cloud:car:edit")
    @Log(title = "冷链车数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbCloudCar tbCloudCar)
    {
        return toAjax(tbCloudCarService.updateTbCloudCar(tbCloudCar));
    }

    /**
     * 删除冷链车数据
     */
    @RequiresPermissions("cloud:car:remove")
    @Log(title = "冷链车数据", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbCloudCarService.deleteTbCloudCarByIds(ids));
    }
}
